﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BlackJack.model
{
    class Game : BlackJack.model.IGameObserver
    {
        private model.Dealer m_dealer;
        private model.Player m_player;
        private List<model.IGameObserver> gameObservers = new List<model.IGameObserver>();

        public Game()
        {
            m_dealer = new Dealer(new rules.RulesFactory());
            m_player = new Player();
        }

        internal IGameObserver IGameObserver
        {
            get
            {
                throw new System.NotImplementedException();
            }
            set
            {
            }
        }

        public bool IsGameOver()
        {
            return m_dealer.IsGameOver();
        }

        public bool IsDealerWinner()
        {
            return m_dealer.IsDealerWinner(m_player, m_dealer);
        }

        public bool NewGame()
        {
            return m_dealer.NewGame(m_player);
        }

        public bool Hit()
        {
            return m_dealer.Hit(m_player);
        }

        public bool Stand()
        {
            return m_dealer.Stand(m_dealer);
        }

        public IEnumerable<Card> GetDealerHand()
        {
            return m_dealer.GetHand();
        }

        public IEnumerable<Card> GetPlayerHand()
        {
            return m_player.GetHand();
        }

        public int GetDealerScore()
        {
            return m_dealer.CalcScore();
        }

        public int GetPlayerScore()
        {
            return m_player.CalcScore();
        }
        public void SubscribeGameObserver(model.IGameObserver gameObserver)
        {
            gameObservers.Add(gameObserver);
        }

        public void UnsubscribeGameObserver(model.IGameObserver gameObserver)
        {
            gameObservers.Remove(gameObserver);
        }

        public void NewCardGiven()
        {
            foreach (var gameObserver in gameObservers)
            {
                gameObserver.NewCardGiven();
            }
        }
    }
}
